home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / hard / drivr / cnetdevice.lha / cnetdevice / src / include / debugs.i < prev    next >
Text File  |  1997-12-21  |  6KB  |  268 lines

  1. ;----------------------------------------------------------------------------
  2. ;                     Debug Info sent to serial port
  3. ;----------------------------------------------------------------------------
  4. ;                        by Bruce Abbott 11-4-97
  5. ;
  6. ; NOTE: If you want to redirect the serial output, execute eg.
  7. ;
  8. ;       run >nil: sushi >"con:50/50/400/160/sushi /auto" NOPROMPT
  9. ;
  10. ;----------------------------------------------------------------------------
  11. ;
  12. ;   types supported  %ld =  32 bit signed decimal
  13. ;                    %lx =  32 bit hex
  14. ;                    %lc =  32 bit char (eg 'ILBM')
  15. ;                    %d  =  16 bit signed decimal
  16. ;                    %x  =  16 bit hex
  17. ;                    %c  =   8 bit character
  18. ;                    %s  =  string pointer (string ends with NULL)
  19. ;
  20. ;   modifiers        0   =  leading spaces for decimal, 0's for hex
  21. ;                  (1-9) =  max number of characters in number
  22. ;
  23. ;
  24. ;   parameters   anything that can be source for 'move.l' instruction
  25. ;
  26. ;   example  bug <"decimal=%03ld, hex=$%03lx">,#27,#$0000001B
  27. ;
  28. ;            prints:- 'decimal= 27, hex=$01b'
  29. ;
  30. ;
  31.  
  32. Bug MACRO   "text",parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8
  33.     IFD     debug
  34.     ifnc    "","\9"
  35.     move.l  \9,-(sp)
  36.     endc
  37.     ifnc    "","\8"
  38.     move.l  \8,-(sp)
  39.     endc
  40.     ifnc    "","\7"
  41.     move.l  \7,-(sp)
  42.     endc
  43.     ifnc    "","\6"
  44.     move.l  \6,-(sp)
  45.     endc
  46.     ifnc    "","\5"
  47.     move.l  \5,-(sp)
  48.     endc
  49.     ifnc    "","\4"
  50.     move.l  \4,-(sp)
  51.     endc
  52.     ifnc    "","\3"
  53.     move.l  \3,-(sp)
  54.     endc
  55.     ifnc    "","\2"
  56.     move.l  \2,-(sp)
  57.     endc
  58.     bsr     bugprintf
  59.     add.w   #(narg-1)*4,sp
  60.     bra.s   .bugend\@
  61. .bugtext\@:
  62.     dc.b    \1,0
  63.     even
  64. .bugend\@:
  65.     ENDC
  66.     ENDM
  67.  
  68.  
  69.  IFD debug
  70.  
  71.  IFND _LVORawPutChar
  72. _LVORawPutChar = -516
  73.  ENDC
  74.  
  75.  
  76. ; do NOT include debugs.i before your startup code!
  77.  
  78. wrongplace:
  79.   moveq   #-1,d0
  80.   rts                   ; abort if start of program!
  81.  
  82.  
  83. bugprintf:
  84.   movem.l d0-d7/a0-a6,-(sp)
  85.   move.l  60(sp),a2     ; point to string (after bsr bugprintf)
  86.   addq.w  #6,a2
  87.   lea     64(sp),a3     ; point to parameters on stack
  88.   move.l  4.w,a6
  89. .rawloop:
  90.   move.b  (a2)+,d0      ; get next char in formatting string
  91.   beq     .done
  92.   moveq   #0,d4
  93.   cmp.b   #'%',d0       ; type id ?
  94.   bne     .print
  95. .gettype:
  96.   move.b  (a2)+,d0
  97.   beq     .done
  98.   cmp.b   #'0',d0
  99.   beq.s   .lead0
  100.   cmp.b   #'9',d0
  101.   bhi.s   .type
  102.   sub.b   #'0',d0
  103.   move.b  d0,d4
  104.   bra.s   .gettype
  105. .lead0:
  106.   bset    #31,d4        ; flag LEADING ZEROS
  107.   bra.s   .gettype
  108. .type:
  109.   cmp.b   #'s',d0       ; string ?
  110.   beq     .dostring
  111.   move.b  d0,d5         ; d5 = last char
  112.   cmp.b   #'l',d0
  113.   bne.s   .dotype
  114.   bset    #30,d4        ; flag LONG SIZE
  115. .donum:
  116.   move.b  (a2)+,d0      ; get type after 'l'
  117.   beq     .done
  118. .dotype:
  119.   cmp.b   #'x',d0       ; hex ?
  120.   beq     .hex
  121.   cmp.b   #'d',d0       ; decimal ?
  122.   beq.s   .dec
  123.   cmp.b   #'c',d0
  124.   beq.s   .char
  125.   bra     .print        ; unsupported type so just print it
  126. .char:
  127.   move.l  (a3)+,d0
  128.   cmp.b   #'l',d5
  129.   bne     .print        ; longword char ?
  130.   subq.w  #1,d4
  131.   bmi.s   .nolen
  132.   move.w  d4,d2
  133.   bra.s   .charloop
  134. .nolen:
  135.   moveq   #3,d2         ; default 4 chars
  136. .charloop:
  137.   rol.l   #8,d0
  138.   jsr     _LVORawPutChar(a6)
  139.   dbf     d2,.charloop
  140.   bra     .rawloop
  141. .dec:
  142.   tst.w   d4
  143.   bne.s   .declen
  144.   move.w  #10,d4        ; default 10 digits
  145. .declen:
  146.   move.l  (a3)+,d3      ; get number
  147.   btst    #30,d4
  148.   bne.s   .declong
  149.   ext.l   d3
  150. .declong:
  151.   tst.l   d3
  152.   bmi.s   .negative
  153.   neg.l   d3
  154.   bra.s   .firstdig
  155. .negative
  156.   moveq   #'-',d0
  157.   jsr     _LVORawPutChar(a6)
  158. .firstdig:
  159.   lea     .dectab(pc),a4
  160.   moveq   #9,d5
  161. .getdiv:
  162.   move.l  (a4)+,d2      ; get divisor
  163.   beq.s   .lastdig
  164.   moveq   #-1,d0
  165. .div10:
  166.   add.l   d2,d3
  167.   dbgt    d0,.div10
  168.   sub.l   d2,d3
  169.   addq.w  #1,d0         ; d0 = -digit
  170.   neg.b   d0
  171.   add.b   #'0',d0       ; d0 = char
  172.   cmp.w   d4,d5
  173.   bhi.s   .skipdec
  174.   btst    #29,d4        ; printed a digit yet ?
  175.   bne.s   .printd
  176.   cmp.b   #'0',d0
  177.   bne.s   .printdec
  178.   btst    #31,d4        ; leading spaces ?
  179.   beq.s   .skipdec
  180.   moveq   #' ',d0       ; lead space
  181.   bra.s   .printd
  182. .printdec:
  183.   bset    #29,d4
  184. .printd:
  185.   jsr     _LVORawPutChar(a6)
  186. .skipdec:
  187.   subq.w  #1,d5
  188.   bra.s   .getdiv
  189. .lastdig:
  190.   neg.b   d3
  191. .zero:
  192.   add.b   #'0',d3
  193.   move.b  d3,d0
  194.   bra.s   .print
  195. .hex:
  196.   btst    #30,d4
  197.   bne.s   .hexlong
  198.   tst.w   d4
  199.   bhi.s   .hexword
  200.   move.w  #4,d4          ; default 4 digits in hex word
  201. .hexword:
  202.   moveq   #3,d2
  203.   move.l  (a3)+,d5
  204.   swap    d5
  205.   bra.s   .hexloop
  206. .hexlong
  207.   tst.w   d4
  208.   bhi.s   .gethexlong
  209.   move.w  #8,d4         ; default 8 digits in hex longword
  210. .gethexlong:
  211.   moveq   #7,d2
  212.   move.l  (a3)+,d5
  213. .hexloop:
  214.   rol.l   #4,d5
  215.   move.w  d5,d0
  216.   and.w   #$000f,d0
  217.   move.b  .hextab(pc,d0.w),d0
  218.   cmp.w   d4,d2
  219.   bhs.s   .skiphex
  220.   cmp.b   #'0',d0       ; '0' ?
  221.   bne.s   .printhex
  222.   btst    #31,d4        ; leading 0's wanted ?
  223.   beq.s   .skiphex
  224. .printhex:
  225.   bset    #31,d4
  226.   jsr     _LVORawPutChar(a6)
  227. .skiphex:
  228.   dbf     d2,.hexloop
  229.   bra     .rawloop
  230. .dostring:
  231.   move.l  (a3)+,d5
  232.   beq.s   .strdone
  233.   exg     d5,a2
  234. .strloop:
  235.   move.b  (a2)+,d0
  236.   beq.s   .strdone
  237.   jsr     _LVORawPutChar(a6)
  238.   bra.s   .strloop
  239. .strdone:
  240.   exg     d5,a2
  241.   bra     .rawloop
  242. .print:
  243.   jsr     _LVORawPutChar(a6)
  244.   bra     .rawloop
  245. .done:
  246.   movem.l (sp)+,d0-d7/a0-a6
  247.   rts
  248.  
  249.  
  250. .hextab:
  251.   dc.b   "0123456789abcdef"
  252.  
  253. .dectab:
  254.   dc.l 100000000
  255.   dc.l 10000000
  256.   dc.l 1000000
  257.   dc.l 100000
  258.   dc.l 10000
  259.   dc.l 1000
  260.   dc.l 100
  261.   dc.l 10
  262.   dc.l 0
  263.  
  264.   cnop 0,4
  265.  
  266.  ENDC
  267.  
  268.